<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>享送小哥</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body class="bg-f">
    <div class="vue">
        <header class="aui-bar aui-bar-nav aui-bar-light u-aui-bar">
            <div class="aui-title u-aui-title">版本更新</div>
        </header>

        <div>
            <img src="../images/logo.png" style="width:8rem;height:8rem;margin:5rem auto 0.5rem auto;">
            <p style="text-align:center;">发现新版：{{version}}</p>
            <div v-if="!progressView" class="aui-btn aui-btn-info aui-btn-block aui-btn-sm" style="width:15rem;margin:3rem auto 0 auto;" @click="update">更新</div>
            <div v-else class="aui-progress aui-progress" style="width:15rem;margin:3rem auto 0 auto;">
                <div class="aui-progress-bar" :style="{width:progress+'%'}">{{progress}}%</div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script>
        apiready = function() {
            app.statusBar.pos();
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                return false;
            });

            vObj = new Vue({
                el: ".vue",
                data: {
                    type: api.pageParam.type,
                    version: api.pageParam.version,
                    url: api.pageParam.url,
                    progressView: 0,
                    progress: 0
                },
                methods: {
                    update: function() {
                        if (this.type == 'ios') {
                            this.iosUpdate();
                        } else {
                            this.androidUpdate();
                        }
                    },
                    iosUpdate: function() {
                        window.location.href = this.url;
                    },
                    androidUpdate: function() {
                        var that = this;
                        that.progressView = 1;
                        api.download({
                            url: this.url,
                            report: true,
                            cache: false,
                            allowResume: false
                        }, function(ret, err) {
                            that.progress = ret.percent
                            if (ret.state == 1) {
                                api.installApp({
                                    appUri: ret.savePath
                                });
                            }
                        });
                    }
                }
            })
        }
    </script>
</body>

</html>
